package route

import (
	"github.com/gin-gonic/contrib/sessions"
	"github.com/gin-gonic/gin"
	"mynetdisk/controller"
)

/**
 *@Author tudou
 *@Date 2019/8/24
 **/

func RouteInit(){
	r:=gin.Default()
	//limiter:=tollbooth.NewLimiter(2,nil)
	store:=sessions.NewCookieStore([]byte("secret"))
	r.Use(sessions.Sessions("mySession",store))
	r.POST("/login",controller.Login)
	r.POST("/register",controller.Register)
	r.GET("/logout",controller.Logout)
	me:=r.Group("/me")
	{
		me.Use(controller.LoginState())
	    me.POST("/upload",controller.UploadOwnFile)
	    me.POST("/upload/more",controller.UploadOwnMutiFile)
		me.POST("/file/set/public",controller.SetFilePublic)
		me.POST("/file/set/personal",controller.SetFilePersonal)
		me.GET("/file/personal",controller.GetPersonalFile)
		me.GET("/file/all",controller.GetUserFile)
		me.GET("/file/public",controller.GetPublicFile)
		me.POST("/file/download/normal",controller.DownloadByName)
		me.POST("/file/password",controller.SharePassword)
		me.POST("/file/share",controller.ShareNormal)
		me.POST("/file/create",controller.CreateDir)
	}

	download:=r.Group("/download")
	{
		download.POST("/password/:uuid",controller.DownloadByPassword)
		download.GET("/share/:uuid",controller.DownloadByRandom)
		download.GET("/point/:uuid",controller.DownloadByPoint)

	}


	r.Run(":8080")
}